package third.redirect_forward;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "Servlet6", value = "/servlet6")
public class Servlet6 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1接受请求
        request.setCharacterEncoding("utf-8");
        System.out.println("浏览器发送:");
        // 2重定向
        // response.sendRedirect("servlet7");
        // request.getContextPath();//返回项目名称
        // response.sendRedirect(request.getContextPath()+"/servlet7");
        // 3转发
        // RequestDispatcher requestDispatcher = request.getRequestDispatcher("/servlet7");
        //  requestDispatcher.forward(request, response);
        request.getRequestDispatcher("/servlet7").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
